package com.yjt.sousou.main;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.sousou.R;
import com.yjt.sousou.main.entity.OrderListEntity;
import com.yjt.sousou.user.LoginTag;
import com.yjt.sousou.utils.HDPreference;
import com.yjt.sousou.widget.LabelView;

import java.util.List;

/**
 * 作者：83734
 * 时间：2018/11/21
 * 描述：
 */
public class OrderListAdapter  extends BaseQuickAdapter<OrderListEntity.DataBean,BaseViewHolder> {

    private ReceiveOrderListener mReceiveOrderListener;
    private OnItemClickListener mOnItemClickListener;
    private String permission;
    public void setReceiveOrderListener(ReceiveOrderListener receiveOrderListener) {
        this.mReceiveOrderListener = receiveOrderListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public OrderListAdapter(int layoutResId, @Nullable List<OrderListEntity.DataBean> data) {
        super(layoutResId, data);
        permission =  HDPreference.getUserId(LoginTag.PERMISSION.name());
    }

    @Override
    protected void convert(BaseViewHolder helper, final OrderListEntity.DataBean item) {
      helper.getView(R.id.ll_item).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(mOnItemClickListener!=null){
                  mOnItemClickListener.onClick(item);
              }
          }
      });
        ImageView iv_receive_order = helper.getView(R.id.iv_receive_order);
        iv_receive_order.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(mReceiveOrderListener!=null){
                  mReceiveOrderListener.clicked(item);
              }
          }
      });
        if(permission.contains("117")&&item.getWxzt().equals("1")){
            iv_receive_order.setVisibility(View.VISIBLE);
        }else {
            iv_receive_order.setVisibility(View.GONE);
        }
        LabelView labelView = helper.getView(R.id.tv_label);
        labelView.setStateStr(item.getWxzt(),item.getRlevel_name());
        helper.setText(R.id.tv_time,item.getVtime());
        helper.setText(R.id.tv_name,item.getBaoxiu());
        helper.setText(R.id.tv_num,item.getOrderid());
        helper.setText(R.id.tv_location,item.getQuyu());
        helper.setText(R.id.tv_des,item.getYuanyin());
    }

    interface ReceiveOrderListener{
        void clicked(OrderListEntity.DataBean item);
    }
    interface OnItemClickListener{
        void onClick(OrderListEntity.DataBean item);
    }
}
